<?php

use App\Helpers\Helper;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Make something great!
|
*/

// Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
//     return $request->user();
// });




Route::post('sessions/login', 'SessionsController@login')->name('login');
Route::get('/verifyCode', 'SessionsController@verifyCode')->name('verifyCode')->description('验证码');

Route::middleware(['auth:api'])->group(function () {
    Route::get('/self', function (Request $request) {
        return $request->user();
    })->name('self');
    Route::put('/self', 'UsersController@selfUpdate')->name('self.update')->description('个人信息:修改');
    
    Route::delete('sessions/logout', 'SessionsController@logout')->name('logout');
    
    Route::get('/home', 'WorkspaceController@home')->name('home')->description('用户主页');
    Route::get('/bigScreen', 'WorkspaceController@BigScreen')->name('BigScreen')->description('大屏');
    Route::get('/provinceScreen', 'WorkspaceController@ProvinceScreen')->name('ProvinceScreen')->description('各省统计');
    Route::get('/region', 'WorkspaceController@region')->name('region')->description('省市区查询');
    Route::post('/cloud_detection', 'WorkspaceController@cloud_detection')->name('cloud_detection.show')->description('智能运检');
    
    Route::get('/weather', 'WorkspaceController@weather')->name('weather')->description('天气预报');
    Route::post('/upload', 'WorkspaceController@upload')->name('upload')->description('上传接口');
    
    Route::middleware(['apiPermission'])->group(function () { 
        //description 为权限
        Route::get('/users', 'UsersController@index')->name('users.index')->description('用户管理:列表');
        Route::post('/users', 'UsersController@store')->name('users.store')->description('用户管理:新增');
        Route::get('/users/{user}', 'UsersController@show')->name('users.show')->description('用户管理:详情');
        Route::put('/users/{user}', 'UsersController@update')->name('users.update')->description('用户管理:修改');
        Route::delete('/users/{user}', 'UsersController@destroy')->name('users.destroy')->description('用户管理:删除');

        Route::get('/roles', 'RolesController@index')->name('roles.index')->description('角色管理:列表');
        Route::post('/roles', 'RolesController@store')->name('roles.store')->description('角色管理:新增');
        Route::get('/roles/{role}', 'RolesController@show')->name('roles.show')->description('角色管理:详情');
        Route::put('/roles/{role}', 'RolesController@update')->name('roles.update')->description('角色管理:修改');
        Route::delete('/roles/{role}', 'RolesController@destroy')->name('roles.destroy')->description('角色管理:删除');

        Route::get('/permissions', 'PermissionsController@index')->name('permission.index')->description('权限管理:列表');
        Route::get('/permissions/flush', 'PermissionsController@flushByRoute')->name('permission.flush')->description('权限管理:刷新权限');

        Route::get('/realtime', 'RealTimeController@show')->name('realtimedata.show')->description('实时数据:实时数据详情');

        Helper::ResourceDescription('enterprise', 'EnterprisesController', '企业管理');

        Helper::ResourceDescription('task', 'TasksController', '任务管理');
        Helper::ResourceDescription('report', 'ReportsController', '任务管理');
        // Helper::ResourceDescription('openapi', 'OpenAPIsController', 'api管理');
        Helper::ResourceDescription('esUnit', 'ESUnitController', '储能单元');
        Route::get('/esUnits/{esUnit}/report', 'ESUnitController@report')->name('esUnits.report')->description('储能单元:查询簇数据');
        Route::get('/esUnits/{esUnit}/predict', 'ESUnitController@predict')->name('esUnits.predict')->description('储能单元:查询簇预测数据');

        Helper::ResourceDescription('esStation', 'ESStationController', '储能站');
        Helper::ResourceDescription('esCluster', 'ESClusterController', '储能簇');
        Route::get('/esClusters/{esCluster}/report', 'ESClusterController@report')->name('esUnits.report')->description('储能簇:查询簇上报');
        Route::get('/esClusters/{esCluster}/predict', 'ESClusterController@predict')->name('esUnits.predict')->description('储能簇:查询簇预测');

        Helper::ResourceDescription('esClusterChargeLog', 'ESClusterChargeLogController', '储能簇实时数据');

        Helper::ResourceDescription('operation', 'OperationController', '运维记录');
        Helper::ResourceDescription('earlyAlarm', 'EarlyAlarmController', '预警记录');
        Helper::ResourceDescription('alarm', 'AlarmController', '告警记录');

        Route::get('/corrections/last', 'CorrectionController@show_last')->name('correction.show_last')->description('最新校正查询');
        Helper::ResourceDescription('analysis', 'AnalysisController', '分析记录');
        Helper::ResourceDescription('correction', 'CorrectionController', '校正查询');

        Route::get('/users/{user}/{info}', 'UsersController@show_info')->name('users.show_info')->description('用户管理:查用户关联信息');
        
    });



});
